package arabicScrabble;

import java.awt.Color;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public abstract class Square extends JPanel {

	int i, j;
	boolean used;
	Letter letter;
	boolean bigBonus;
	int bonus;
	Color colour;
	BufferedImage img;

	public Square(int i, int j) {
		this.i = i;
		this.j = j;
		used = false;
		bigBonus = false;
		setOpaque(true);
	}

	public int getBonus() {
		return bonus;
	}

	public boolean getBigBonus() {
		return bigBonus;
	}

	public Letter getLetter() {
		return letter;
	}

	public int getI() {
		return i;
	}

	public int getJ() {
		return j;
	}

	public void setXi(int i) {
		this.i = i;
	}

	public void setYj(int j) {
		this.j = j;
	}

	public void setLetter(Letter l) {
		letter = l;
	}

	public void setUsed(boolean used) {
		this.used = used;
		// bonus = 1;
	}

	public boolean isUsed() {
		return used;
	}

	public void placeTile(Letter i) {
		letter = i;
		used = true;

	}

	public void remove(Letter x) {
		// super.remove(x);
		letter = null;

	}

	@Override
	public java.awt.Component add(java.awt.Component comp) {

		Letter x = (Letter) comp;
		// super.add(x);
		letter = x;
		x.square=this;

		return x;

	}

	@Override
	public void paint(Graphics g) {
		// super.paint(g);
		// this.setOpaque(false);
		if (letter == null) {
			g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null);
		} else {
			g.drawImage(letter.img, 0, 0, this.getWidth(), this.getHeight(),
					null);
		}
	}
	
	@Override
	public String toString() {
		try{
	return "x:"+i+" y:" +j+ "\n" + "let "+letter.symbol;
		}catch (Exception e) {
			return "x:"+i+" y:"+j+ "\n" +"let:"+letter;
		}
	}

}
